<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<!--修改审核人-->
<div class="modal fade" data-backdrop="static" data-keyboard="false" id="modal-edit">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">修改上级审核人</h4>
            </div>
            <div class="modal-body">
                <form id="editForm" class="form-horizontal">
                    <input type="hidden" name="id">
                    <div class="col-md-12">
                        <div class="form-group">
                            <label class="col-sm-4 control-label" for="verifier">审核人</label>
                            <div class="col-sm-8">
                                <select id="verifier" class="form-control" name="verifier">
                                    <option value="" selected>请选择</option>
                                    <option th:each="user : ${users}" th:value="${user.id}"
                                            th:text="${user.name}"></option>
                                </select>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button  type="button" class="btn btn-info" id="btn-edit">
                    确定
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" data-backdrop="static" data-keyboard="false" id="modal-edit-second">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">修改第二提报人</h4>
            </div>
            <div class="modal-body">
                <form id="editSecondForm" class="form-horizontal">
                    <input type="hidden" name="id">
                    <div class="form-group">
                        <label class="col-sm-4 control-label" for="verifier">原提报人</label>
                        <div class="col-sm-8">
                            <input id="postName" type="text" class="form-control" disabled>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group">
                            <label class="col-sm-4 control-label" for="verifier">提报人</label>
                            <div class="col-sm-8">
                                <select id="createId" class="form-control" name="createId">
                                    <option value="" selected>请选择</option>
                                    <option th:each="user : ${secondUsers}" th:value="${user.id}"
                                            th:text="${user.name}"></option>
                                </select>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button shiro:haspermission="report:check:edit" type="button" class="btn btn-info" id="btn-edit-second">
                    确定
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<section class="content-header">
    <h1>提报计划审核</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-proCode">项目编号</label>
                                    <input id="query-proCode" type="text" name="proCode" class="form-control"
                                           placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label for="query-proName">项目名称</label>
                                    <input id="query-proName" type="text" name="proName" class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label for="query-malType">类型</label>
                                    <select id="query-malType" class="form-control" name="malType">
                                        <option value="" selected>请选择</option>
                                        <option th:each="type : ${malTypes}" th:value="${type.name}"
                                                th:text="${type.name}"></option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-part">部分</label>
                                    <input id="query-part" type="text" name="part" class="form-control"
                                           placeholder="请输入部分">
                                </div>
                                <div class="form-group">
                                    <label for="query-rejectStatus">状态</label>
                                    <select id="query-rejectStatus" class="form-control" name="rejectStatus">
                                        <option value="">请选择</option>
<!--                                        <option value="0">被撤回</option>-->
                                        <option value="1" selected>未审核</option>
                                        <option value="2">已审核</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-postName">提报人</label>
                                    <input id="query-postName" type="text" name="postName" class="form-control"
                                           placeholder="请输入提报人">
                                </div>
                                <div class="form-group">
                                    <label for="query-startTime">提报日期</label>
                                    <input id="query-startTime" type="text" class="form-control datepicker" name="startTime"
                                           readonly="readonly"/>
                                    <label for="query-endTime"> 至 </label>
                                    <input id="query-endTime" type="text" class="form-control datepicker" name="endTime"
                                           readonly="readonly"/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    let table, typeName = ['', '外购件', '外协件', '原材料'], sheetType = ['','提报单','变更单'];

    /** 修改审核人模态框 */
    function openEditModal(id) {
        $("#editForm input[name=id]").val(id);
        js.modal.open('modal-edit')
    }

    /** 修改审核人模态框 */
    function openEditSecond(id,name) {
        $("#editSecondForm input[name=id]").val(id);
        $("#editSecondForm #postName").val(name);
        js.modal.open('modal-edit-second')
    }

    /** 确认继续审核 */
    function confirmVerify(id) {
        js.modal.confirm("请确认已经选择上级审核人, 继续审核将无法修改你的上级审核人，确认继续吗？", function () {
            location.href = ctx + "report/check/" + id;
        })
    }

    $(function () {

        /** 加载列表 */
        table = js.table.init({
            url: ctx + "report/check/list",
            columns: [
                {title: '序号', field: 'id', width: '50px',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                // {title: "表单编号", field: 'batchNo'},
                {title: "分类", field: 'reportType',
                    formatter: function (value) {
                        /*if (value === 1) {
                            return '<span class="badge label-success">外购件</span>';
                        } else if (value === 2) {
                            return '<span class="badge label-warning">外协件</span>';
                        } else if (value === 3) {
                            return '<span class="badge label-inverse">原材料</span>';
                        }*/
                        return typeName[value];
                    }
                },
                {title: "项目编号", field: 'proCode'},
                {title: "项目名称", field: 'proName'},
                {title: "项目数量", field: 'proNum'},
                {title: "类型", field: 'malType'},
                {title: "部分", field: 'part'},
                {title: "提报类型", field: 'sheetType',
                    formatter: function (value) {
                        /*if (value === 1) {
                            return '<span class="badge label-primary">提报单</span>';
                        } else if (value === 2) {
                            return '<span class="badge label-warning">变更单</span>';
                        }*/
                        return sheetType[value];
                    }
                },
                {title: "审核状态", field: 'rejectStatus',
                    formatter: function (value) {
                        /*if (value === 0) {
                            return '<span class="badge label-danger">被驳回</span>';
                        } else if (value === 1) {
                            return '<span class="badge label-warning">未审核</span>';
                        } else if (value === 2) {
                            return '<span class="badge label-success">已审核</span>';
                        }*/
                        if (value === 2) {
                            return '<span class="badge label-success">已审核</span>';
                        } else {
                            return '<span class="badge label-warning">未审核</span>';
                        }
                    }
                },
                {title: "提报人", field: 'postName'},
                // {title: "审核人", field: 'verifyName'},
                {title: "驳回原因", field: 'rejectReason', width: '100px'},
                {title: "提报日期", field: 'commitTime'},
                {
                    title: "操作",
                    // width: '250',
                    formatter: function (value, row) {
                        let actions = [];
                        if (row.cur === 0) {
                            actions.push('<a class="btn btn-info btn-xs" target="_blank" href="' + ctx + 'report/check/info/' + row.id + '" > 查看</a>');
                        }
                        if (row.cur === 1) {
                            if (hasP("report:check:editVerify")) {
                                actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="confirmVerify(' + row.id + ')" > 审核</a>');
                            } else {
                                actions.push('<a class="btn btn-warning btn-xs" href="' + ctx + 'report/check/' + row.id + '" > 审核</a>');
                            }
                        }
                        if (row.start === 1 && row.rejectStatus === 2 && hasP("report:check:second")) {
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openEditSecond(' + row.id + ',\'' + row.postName + '\')" > 修改第二提报人</a>');
                        }
                        if (row.comp === 0 && row.rejectStatus === 1 && hasP("report:check:editVerify")) {
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openEditModal(' + row.verifyProcessId + ')"> 修改上级审核人</a>');
                        }
                        if (row.comp === 1 && row.rejectStatus === 2 && row.sheetType === 2) {
                            actions.push('<a class="btn btn-warning btn-xs" href="' + ctx + 'report/check/cancel/' + row.id + '" > 撤消变更</a>');
                        }
                        return actions.join('');
                    }
                }
            ]
        });

        /** 验证规则 */
        js.validate.init("editForm", {
            fields: {
                verifier: {validators: {notEmpty: {message: '请选择审核人'}}}
            }
        });
        /** 修改审核人 */
        $("#btn-edit").click(function () {
            js.validSubmit({
                formId: "editForm",
                url: ctx + "report/check/edit",
                data: new FormData($("#editForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.modal.hide("modal-edit");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });
        js.modal.hideEvent("modal-edit", function () {
            js.validate.reset("editForm");
            js.reset("editForm");
        });

        /** 验证规则 */
        js.validate.init("editSecondForm", {
            fields: {
                createId: {validators: {notEmpty: {message: '请选择提报人'}}}
            }
        });
        /** 修改审核人 */
        $("#btn-edit-second").click(function () {
            js.validSubmit({
                formId: "editSecondForm",
                url: ctx + "report/check/editReport",
                data: new FormData($("#editSecondForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.modal.hide("modal-edit-second");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });
        js.modal.hideEvent("modal-edit", function () {
            js.validate.reset("editSecondForm");
            js.reset("editSecondForm");
        });

    });
</script>
</body>
</html>
